package si.yun.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import si.yun.dao.PersonnelDao;
import si.yun.entity.PerCount;
import si.yun.entity.SyBeforeUser;
import si.yun.entity.SyClosure;
import si.yun.service.PersonnelService;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: SiYunClass
 * @description: 人事业务层
 * @author: 崔晓晨
 * @create: 2021-07-28 20:50
 **/
@Service
public class PersonnelServiceImpl implements PersonnelService {
    @Autowired
    private PersonnelDao personnelDao;
    /**
     * @Description  查询用户的数据展示
     * @return si.yun.entity.PerCount
     * @Date 2021/7/29 14:19
     **/
    @Override
    public PerCount selUserNum() {
        PerCount p = new PerCount();
        int today = personnelDao.selUserToday();
        int yes = personnelDao.selUserYes();
        int mou = personnelDao.selUserMou();
        int Num = personnelDao.selUserNum();
        int passNum = personnelDao.selapplyPassNum();
        int afterUserNum = personnelDao.selAfterUserNum();
        int fee = personnelDao.selFeedBackWaitNum();
        int waitNum = personnelDao.selApplyWaitNum();
        p.setUserMou(mou);
        p.setUserNum(Num);
        p.setUserYes(yes);
        p.setUserToday(today);
        p.setAfterUserNum(afterUserNum);
        p.setApplyPassNum(passNum);
        p.setFeedbackWaitNum(fee);
        p.setApplyWaitNum(waitNum);
        return p;
    }
    /**
     * @Description  获取期间内申请人员统计信息
     * @return si.yun.entity.PerCount 
     * @Date 2021/7/28 21:32
     **/
    @Override
    public PerCount selPerTab(int durDate) {
        int perCount = personnelDao.selApplyNum();
        int perPass = personnelDao.selApplyPass(durDate);
        int applyRejection = personnelDao.selApplyRejection(durDate);
        String applyPosition = personnelDao.selApplyPosition(durDate);
        PerCount p = new PerCount();
        p.setApplyNum(perCount);
        p.setApplyPass(perPass);
        p.setApplyRejection(applyRejection);
        p.setApplyPosition(applyPosition);
        return p;
    }
    /**
     * @Description 获取用户统计量
     * @return list<Integer>
     * @Date 2021/7/29 13:28
     **/
    @Override
    public List<Integer> selUserEcharts() {
        int day1 = personnelDao.selUserday1();
        int day2 = personnelDao.selUserday2();
        int day3 = personnelDao.selUserday3();
        int day4 = personnelDao.selUserday4();
        int day5 = personnelDao.selUserday5();
        int day6 = personnelDao.selUserday6();
        int day7 = personnelDao.selUserday7();
        List<Integer> list = new ArrayList<>();
        list.add(day1);
        list.add(day2);
        list.add(day3);
        list.add(day4);
        list.add(day5);
        list.add(day6);
        list.add(day7);
        return list;
    }
    /**
     * @Description  获取用户列表
     * @return java.util.List<si.yun.entity.SyBeforeUser> 
     * @Date 2021/7/29 19:22
     **/
    @Override
    public List<SyBeforeUser> selUserTable(SyBeforeUser beforeUser) {
        List<SyBeforeUser> beforeUsers = personnelDao.selUserTable(beforeUser);
        return beforeUsers;
    }

    /**
     * @Description  添加停用的用户
     * @return int
     * @Date 2021/8/1 18:37
     **/
    @Transactional
    @Override
    public int addClosure(SyClosure closure) {
        int add = personnelDao.addClosure(closure);
        updBeforeStatus(closure.getUserId(),3);
        return add;
    }
    /**
     * @Description  查询单个用户的详细信息
     * @return si.yun.entity.SyBeforeUser 
     * @Date 2021/8/1 19:00
     **/
    @Override
    public SyBeforeUser selUserInfo(int userId) {
        SyBeforeUser beforeUser = personnelDao.selUserInfo(userId);
        return beforeUser;
    }
    /**
     * @Description  编译用户信息 ( 不能编译用户的学习时长  和 交易金额 以及 账号创建时间)
     * @return int 
     * @Date 2021/8/1 21:00
     **/
    @Override
    public int updSelUser(SyBeforeUser beforeUser) {
        int upd = personnelDao.updSelUser(beforeUser);
        return upd;
    }
    /**
     * @Description  查询封号用户列表
     * @return java.util.List<si.yun.entity.SyClosure>
     * @Date 2021/8/2 9:43
     **/
    @Override
    public List<SyClosure> selClosureUserTable(SyClosure closure) {
        List<SyClosure> closures = personnelDao.selClosureUserTable(closure);
        return closures;
    }
    /**
     * @Description  解封用户 改变封号列表信息
     * @return int 
     * @Date 2021/8/2 15:12
     **/
    @Override
    @Transactional
    public int updClosure(SyClosure closure) {
        String reason = closure.getReason();
        closure.setReason(reason+"(已解封)");
        int upd = personnelDao.updClosure(closure);
        int userId = closure.getUserId();
        int status = 2;
        updBeforeStatus(userId,status);
        return upd;
    }
    /**
     * @Description  更改用户账号的状态
     * @return int
     * @Date 2021/7/30 14:37
     **/
    public int updBeforeStatus(int userId,int status) {
        int upd = personnelDao.updBeforeStatus(userId,status);
        return upd;
    }
    /**
     * @Description  删除停用后的封停日志
     * @return int
     * @Date 2021/7/30 15:39
     **/
    @Override
    public int delBeforeStatus(int id) {
        int del = personnelDao.delBeforeStatus(id);
        return del;
    }
}
